passed checkstyle and tests#1795
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This implementation has two critical violations of the task requirements that must be fixed before approval. First, the code imports and uses java.util.Arrays (line 3) and calls Arrays.copyOf() in the ensureCapacity() method, which explicitly violates the technical constraint 'Do not use Objects, Arrays, or any other util class.' You must replace this with a manual implementation using System.arraycopy() to create a new array and copy elements. Second, the constructor initializes the internal array with new Object[DEFAULT_CAPACITY], pre-allocating 10 elements. This differs from java.util.ArrayList behavior, which starts with an empty internal array—capacity 10 should only be allocated when the first element is added (lazy initialization). Please fix both issues and resubmit.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| @@ -1,48 +1,119 @@ | |||
| package core.basesyntax; | |||
|
|
|||
| import java.util.Arrays; | |||
There was a problem hiding this comment.
This violates the technical constraint: 'Do not use Objects, Arrays, or any other util class.' The task explicitly prohibits using the Arrays class. Use System.arraycopy() to copy arrays instead of Arrays.copyOf().
| private int size; | ||
|
|
||
| public ArrayList() { | ||
| this.elementData = new Object[DEFAULT_CAPACITY]; |
There was a problem hiding this comment.
According to the task requirements, the default capacity should match java.util.ArrayList behavior which starts with an EMPTY internal array. The capacity should become 10 only when the first element is added (via ensureCapacity logic), not pre-allocated in the constructor.
| : (int) (elementData.length * 1.5); | ||
| if (newLength < minCapacity) { | ||
| newLength = minCapacity; | ||
| } |
There was a problem hiding this comment.
Replace Arrays.copyOf() with a manual implementation using System.arraycopy() to avoid using the Arrays class. Create a new temporary array and copy elements manually.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your ArrayList implementation is approved and meets all requirements. The code successfully implements lazy initialization in the constructor (empty array created, capacity allocated only when needed), uses System.arraycopy() for array operations, and includes all required functionality: default capacity of 10 with 1.5x growth factor, proper exception handling for invalid indices and missing elements, and extracted helper methods for index validation and capacity management. All checklist items pass, and no test failures were reported. Great work addressing the previous review feedback!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.